package com.itlong.cloud.controller.sharedelevator;

import com.alibaba.fastjson.JSON;
import com.itlong.cloud.POJO.DTO.property.PaymentRecordDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.property.PropertyPaymentRecordVO;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.paymenthub.IPropertyPaymentServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <desc>
 *      运营-缴费管理控制器
 * </desc>
 *
 * @createDate2020/7/15
 **/
@RestController
@RequestMapping("/sharedElevator/payment")
public class OperatePaymentController {

    @Autowired
    private IPropertyPaymentServiceClient iPropertyPaymentServiceClient;

    /**
     * <desc>
     *      分页获取缴费记录
     * </desc>
     *
     * @param paymentRecordDTO 缴费记录DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/7/15
     */
    @RequestMapping(value = "/getPage", method = RequestMethod.POST)
    public Object getPage(PaymentRecordDTO paymentRecordDTO, HttpServletRequest request){
        try{
            Map<String, Object> result = new HashMap<>();
            paymentRecordDTO = HttpProtocolUtil.parseRequestParamToDTO(PaymentRecordDTO.class, request);
            if (paymentRecordDTO == null){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<PropertyPaymentRecordVO> page = iPropertyPaymentServiceClient.getPage(paymentRecordDTO);
            String totalAmount = iPropertyPaymentServiceClient.getPaymentPriceCount(paymentRecordDTO);
            result.put("totalAmount", totalAmount);
            return new MessageVO(JSON.toJSONString(result), BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);
        }catch (Exception e){
            throw new DataAccessException("【运营_缴费管理_分页获取缴费记录getPage】分页获取缴费记录失败", e);
        }
    }
}
